/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cse308.entities;

import cse308.GeneralEntity;
import cse308.helper_classes.GeneralTest;
import cse308.helper_classes.StudentOutcomeClass;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Aaron
 */
@Entity
@Table(catalog = "nchorn", schema = "")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Studentoutcome.findAll", query = "SELECT s FROM Studentoutcome s"),
    @NamedQuery(name = "Studentoutcome.findByIdentifier", query = "SELECT s FROM Studentoutcome s WHERE s.identifier = :identifier"),
    @NamedQuery(name = "Studentoutcome.findBySequencenumber", query = "SELECT s FROM Studentoutcome s WHERE s.sequencenumber = :sequencenumber"),
    @NamedQuery(name = "Studentoutcome.findByShortname", query = "SELECT s FROM Studentoutcome s WHERE s.shortname = :shortname"),
    @NamedQuery(name = "Studentoutcome.findByDescription", query = "SELECT s FROM Studentoutcome s WHERE s.description = :description"),
    @NamedQuery(name = "Studentoutcome.findByTargetdirectassessmentattainmentlevels", query = "SELECT s FROM Studentoutcome s WHERE s.targetdirectassessmentattainmentlevels = :targetdirectassessmentattainmentlevels"),
    @NamedQuery(name = "Studentoutcome.findByTargetsurveyasseessmentattainmentlevels", query = "SELECT s FROM Studentoutcome s WHERE s.targetsurveyasseessmentattainmentlevels = :targetsurveyasseessmentattainmentlevels"),
    @NamedQuery(name = "Studentoutcome.findBySemester", query = "SELECT s FROM Studentoutcome s WHERE s.semester = :semester"),
    @NamedQuery(name = "Studentoutcome.findByYea", query = "SELECT s FROM Studentoutcome s WHERE s.yea = :yea"),
    @NamedQuery(name = "Studentoutcome.findByEndsemester", query = "SELECT s FROM Studentoutcome s WHERE s.endsemester = :endsemester"),
    @NamedQuery(name = "Studentoutcome.findByEndyear", query = "SELECT s FROM Studentoutcome s WHERE s.endyear = :endyear"),
    @NamedQuery(name = "Studentoutcome.findByDegreeprogramAlt", query = "SELECT s FROM Studentoutcome s WHERE s.degreeprogramAlt = :degreeprogramAlt"),
    @NamedQuery(name = "Studentoutcome.findByDegreeProgramString", query = "SELECT s FROM Studentoutcome s WHERE s.degreeprogram.identifier = :degreeProgramString")
})
public class Studentoutcome implements Serializable, GeneralEntity {

    private static final long serialVersionUID = 1L;
    @Id
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 20)
    @Column(nullable = false, length = 20)
    private String identifier;
    @Basic(optional = false)
    @NotNull
    @Column(nullable = false)
    private int sequencenumber;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 5)
    @Column(nullable = false, length = 5)
    private String shortname;
    @Basic(optional = false)
    @NotNull
    @Size(min = 1, max = 120)
    @Column(nullable = false, length = 120)
    private String description;
    @Size(max = 20)
    @Column(length = 20)
    private String targetdirectassessmentattainmentlevels;
    @Size(max = 20)
    @Column(length = 20)
    private String targetsurveyasseessmentattainmentlevels;
    private Integer semester;
    private Integer yea;
    private Integer endsemester;
    private Integer endyear;
    @Size(max = 20)
    @Column(length = 20)
    private String degreeprogramAlt;
    @JoinColumn(name = "degreeprogram", referencedColumnName = "identifier")
    @ManyToOne
    private Degreeprogram degreeprogram;
    @OneToMany(mappedBy = "studentoutcome")
    private Collection<Courseoutcome> courseoutcomeCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "studentoutcome1")
    private Collection<Targetsurveyassessment> targetsurveyassessmentCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "studentoutcome1")
    private Collection<Targetdirectassessment> targetdirectassessmentCollection;

    public Studentoutcome() {
        this.courseoutcomeCollection = new ArrayList();
        this.targetdirectassessmentCollection = new ArrayList();
        this.targetsurveyassessmentCollection = new ArrayList();
    }

    public Studentoutcome(String identifier) {
        this.identifier = identifier;
        this.courseoutcomeCollection = new ArrayList();
        this.targetdirectassessmentCollection = new ArrayList();
        this.targetsurveyassessmentCollection = new ArrayList();
    }

    public Studentoutcome(String identifier, int sequencenumber, String shortname, String description) {
        this.identifier = identifier;
        this.sequencenumber = sequencenumber;
        this.shortname = shortname;
        this.description = description;
        this.courseoutcomeCollection = new ArrayList();
        this.targetdirectassessmentCollection = new ArrayList();
        this.targetsurveyassessmentCollection = new ArrayList();
    }

    public String getIdentifier() {
        return identifier;
    }

    public void setIdentifier(String identifier) {
        this.identifier = identifier;
    }

    public int getSequencenumber() {
        return sequencenumber;
    }

    public void setSequencenumber(int sequencenumber) {
        this.sequencenumber = sequencenumber;
    }

    public String getShortname() {
        return shortname;
    }

    public void setShortname(String shortname) {
        this.shortname = shortname;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getTargetdirectassessmentattainmentlevels() {
        return targetdirectassessmentattainmentlevels;
    }

    public void setTargetdirectassessmentattainmentlevels(String targetdirectassessmentattainmentlevels) {
        this.targetdirectassessmentattainmentlevels = targetdirectassessmentattainmentlevels;
    }

    public String getTargetsurveyasseessmentattainmentlevels() {
        return targetsurveyasseessmentattainmentlevels;
    }

    public void setTargetsurveyasseessmentattainmentlevels(String targetsurveyasseessmentattainmentlevels) {
        this.targetsurveyasseessmentattainmentlevels = targetsurveyasseessmentattainmentlevels;
    }

    public Integer getSemester() {
        return semester;
    }

    public void setSemester(Integer semester) {
        this.semester = semester;
    }

    public Integer getYea() {
        return yea;
    }

    public void setYea(Integer yea) {
        this.yea = yea;
    }

    public Integer getEndsemester() {
        return endsemester;
    }

    public void setEndsemester(Integer endsemester) {
        this.endsemester = endsemester;
    }

    public Integer getEndyear() {
        return endyear;
    }

    public void setEndyear(Integer endyear) {
        this.endyear = endyear;
    }

    public String getDegreeprogramAlt() {
        return degreeprogramAlt;
    }

    public void setDegreeprogramAlt(String degreeprogramAlt) {
        this.degreeprogramAlt = degreeprogramAlt;
    }

    public Degreeprogram getDegreeprogram() {
        return degreeprogram;
    }

    public void setDegreeprogram(Degreeprogram degreeprogram) {
        this.degreeprogram = degreeprogram;
    }

    @XmlTransient
    public Collection<Courseoutcome> getCourseoutcomeCollection() {
        return courseoutcomeCollection;
    }

    public void setCourseoutcomeCollection(Collection<Courseoutcome> courseoutcomeCollection) {
        this.courseoutcomeCollection = courseoutcomeCollection;
    }

    @XmlTransient
    public Collection<Targetsurveyassessment> getTargetsurveyassessmentCollection() {
        return targetsurveyassessmentCollection;
    }

    public void setTargetsurveyassessmentCollection(Collection<Targetsurveyassessment> targetsurveyassessmentCollection) {
        this.targetsurveyassessmentCollection = targetsurveyassessmentCollection;
    }

    @XmlTransient
    public Collection<Targetdirectassessment> getTargetdirectassessmentCollection() {
        return targetdirectassessmentCollection;
    }

    public void setTargetdirectassessmentCollection(Collection<Targetdirectassessment> targetdirectassessmentCollection) {
        this.targetdirectassessmentCollection = targetdirectassessmentCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (identifier != null ? identifier.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Studentoutcome)) {
            return false;
        }
        Studentoutcome other = (Studentoutcome) object;
        if ((this.identifier == null && other.identifier != null) || (this.identifier != null && !this.identifier.equals(other.identifier))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "cse308.entities.Studentoutcome[ identifier=" + identifier + " ]";
    }

    @Override
    public List<List<GeneralEntity>> getAssociatedClasses() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public List<GeneralEntity> getAssociatedClass(String associated) {
        ArrayList<GeneralEntity> toReturn = new ArrayList();
        if (associated.equals(Degreeprogram.class.getSimpleName())) {
            toReturn.add(this.degreeprogram);
        }
        return toReturn;
    }

    @Override
    public void setWithClass(GeneralTest gt) {
        /*
         *   this.identifier = entity.getIdentifier();
         this.sequenceNumber = entity.getSequencenumber();
         this.shortName = entity.getShortname();
         this.description = entity.getDescription();
         this.targetDirectAssessmentAttainmentLevel = new HashMap();
         this.targetSurveyAssessmentAttainmentLevel = new HashMap();
         */
        StudentOutcomeClass so = (StudentOutcomeClass) gt;
        this.identifier = so.getIdentifier();
        this.sequencenumber = so.getSequenceNumber();
        this.shortname = so.getShortName();
        this.description = so.getDescription();
    }

    @Override
    public void testAddClass(GeneralEntity ge) {
        //Targetsurveyassessment. Targetdirectassessment
        if (ge instanceof Targetsurveyassessment) {
            this.targetsurveyassessmentCollection.add((Targetsurveyassessment) ge);
        } else if (ge instanceof Targetdirectassessment) {
            this.targetdirectassessmentCollection.add((Targetdirectassessment) ge);
        }
    }

    @Override
    public void removeClass(GeneralEntity ge) {
        if (ge instanceof Targetsurveyassessment) {
            this.targetsurveyassessmentCollection.remove((Targetsurveyassessment) ge);
        } else if (ge instanceof Targetdirectassessment) {
            this.targetdirectassessmentCollection.remove((Targetdirectassessment) ge);
        }
    }

    @Override
    public String getIdentifier2() {
        return this.identifier;
    }

    @Override
    public GeneralEntity findCorrespondingEntity() {
        return this;
    }

    @Override
    public boolean equalsEntity(GeneralEntity entity) {
        return this.equals(entity);
    }

    @Override
    public Object getPK() {
        return this.identifier;
    }
}
